package com.tedu.sp04.order.service;

import com.tedu.sp01.pojo.Item;
import com.tedu.sp01.pojo.Order;
import com.tedu.sp01.pojo.User;
import com.tedu.sp01.service.OrderService;
import com.tedu.sp01.util.JsonResult;
import com.tedu.sp04.feign.ItemClient;
import com.tedu.sp04.feign.UserClient;
import jdk.nashorn.internal.runtime.logging.DebugLogger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    private UserClient userClient;
    @Autowired
    private ItemClient itemClient;
    @Override
    public Order getOrder(String orderId) {
        JsonResult<List<Item>> items=itemClient.getItems(orderId);
        JsonResult<User> user=userClient.getUser(8);
       //远程调用商品，获取
        Order order=new Order();
        order.setId(orderId);
        order.setUser(user.getData());
        order.setItems(items.getData());
        return order;
    }

    @Override
    public void addOrder(Order order) {
        DebugLogger log = null;
        log.info("保存订单："+order);
        //远程调用减少库存
        itemClient.decreaseNumber(order.getItems());
        //远程调用增加用户积分
        userClient.addScore(order.getUser().getId(), 1000);

    }
}
